package com.gxuwz.medical.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gxuwz.medical.domain.family.Family;
import com.gxuwz.medical.domain.institution.Institution;
import com.gxuwz.medical.domain.register.Register;

/**
 * 参合登记管理控制处理
 * @author 沉羽墨玖
 *
 */
public class RegisterServlet extends BaseServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String  m=request.getParameter("m");
		try{
		if("list".equals(m)){
			process(request, response, "/page/register/register_list.jsp");
		}else if("list2".equals(m)){
			process(request, response, "/page/register/register_list2.jsp");
		}else if("input".equals(m)){
			process(request, response, "/page/register/register_add.jsp");
		}else if("add".equals(m)){
			add(request, response);
		}else if("del".equals(m)){
			del(request, response);
		}
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	/**
	 * 添加参合登记
	 * @throws Exception 
	 */
	private void add(HttpServletRequest request, HttpServletResponse response)
			throws Exception{
		String persCode=request.getParameter("persCode");
		String famCode=request.getParameter("famCode");
		 String persName=request.getParameter("persName");
		 String cardId=request.getParameter("cardId");
		 String sex=request.getParameter("sex");
		 String ageNo=request.getParameter("age");
		 int age=Integer.parseInt(ageNo);
		 String illName=request.getParameter("illName");
		 String liveAddress=request.getParameter("liveAddress");
		 String telephone=request.getParameter("telephone");
		 String createTime=request.getParameter("createTime");
		 //String invoice=request.getParameter("invoice");
		 //实例化Institution类
		 Register register = new Register();
		 Family family =new Family();
		 family.setFamCode(famCode);
		 register.setPersCode(persCode);
		 register.setFamily(family);
		 register.setPersName(persName);
		 register.setCardId(cardId);
		 register.setSex(sex);
		 register.setAge(age);
		 register.setIllName(illName);
		 register.setLiveAddress(liveAddress);
		 register.setTelephone(telephone);
		 register.setCreateTime(createTime);
		// register.setInvoice(invoice);
		 try{
			 register.add();
		  	 process(request, response, "/page/register/register_list.jsp");
		  }catch(Exception e){
		  		e.printStackTrace();
		  	  }
		 
	}

private void del(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{
	  //1：接收参数
	  String persCode=req.getParameter("persCode");
	  //2:构造新慢病信息对象
	  Register register=new Register();
	  try{
		  register.del(persCode);
		process(req, resp, "/page/register/register_list.jsp");
	  }catch(Exception e){
		e.printStackTrace();
	  }
	}
}
